import com.google.gson.Gson;
import gremlin.GremlinInstance;
import json.*;
import java.io.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import com.google.gson.GsonBuilder;
import database.*;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;

public class ParseAndStore {
    public static void main(String[] args) throws IOException {
        File PDGDirectory = new File("output/PDG/");
        File[] PDGFiles = PDGDirectory.listFiles();
        AllFileTotal allFileTotal = new AllFileTotal();
        FileSystem fileSystem = new FileSystem();
        if (PDGFiles != null && PDGFiles.length > 0) {
            for (File PDGFile : PDGFiles) {
                String hashCode = PDGFile.getName().substring(0, PDGFile.getName().indexOf('.'));
                File ASTFile = new File("output/AST/" + hashCode + ".json");
                File CFGFile = new File("output/CFG/" + hashCode + ".txt");
                if (ASTFile.exists() && CFGFile.exists()) {
                    SingleFileTotal singleFileTotal = parsePDG(PDGFile, ASTFile);
                    SingleFileTotal tmpSingleFileTotal = parseCFG(CFGFile, ASTFile);
                    database.File file = new database.File(singleFileTotal.fileName.replace("\\", "/"));
                    fileSystem.fileList.add(file);
                    fileSystem.folderList.addAll(getFolderListbyFilePath(fileSystem.folderList, file.fileName));
                    for (Code CFGCode : tmpSingleFileTotal.codeList) {
                        boolean hasCode = false;
                        for (Code PDGCode : singleFileTotal.codeList) {
                            if (CFGCode.codeLabel.equals(PDGCode.codeLabel) && CFGCode.lineno.equals(PDGCode.lineno)) {
                                hasCode = true;
                                break;
                            }
                        }
                        if (!hasCode) {
                            singleFileTotal.codeList.add(CFGCode);
                        }
                    }
                    singleFileTotal.cfgList.addAll(tmpSingleFileTotal.cfgList);
                    allFileTotal.singleFileTotalList.add(singleFileTotal);
                } else {
                    System.out.println("Lack AST or CFG!");
                }
            }
        } else {
            System.out.println("Null Directory!");
        }
        File CGSumDirectory = new File("output/CG/");
        File[] CGDirectories = CGSumDirectory.listFiles();
        if(CGDirectories != null && CGDirectories.length > 0){
            for(File CGDirectory : CGDirectories){
                File[] CGFiles = CGDirectory.listFiles();
                if(CGFiles != null && CGFiles.length > 0){
                    for(File CGFile:CGFiles){
                        allFileTotal.cgList.addAll(parseCG(CGFile));
                    }
                }
            }
        }
        storeDB(allFileTotal);
        //Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
        //System.out.println(666);
        //System.out.println(gson.toJson(allFileTotal));
        //System.out.println(gson.toJson(fileSystem));
    }

    public static void storeDB(AllFileTotal allFileTotal){
        GraphTraversalSource g = GremlinInstance.getInstance().get();
        try {
            for(SingleFileTotal singleFileTotal : allFileTotal.singleFileTotalList){
                for(Code code : singleFileTotal.codeList){
                    g.addV("Code")
                            .property("json", code.json)
                            .property("lineno", code.lineno)
                            .property("belongFile", code.belongFile)
                            .property("functionDefName", code.functionDefName)
                            .next();
                    /*System.out.println(code.codeLabel);
                    System.out.println(code.json);
                    System.out.println(code.lineno);*/
                }
                for(Method method : singleFileTotal.methodList){
                    System.out.println(method.methodAST);
                    System.out.println(method.methodLineNo);
                    System.out.println(method.belongFile);
                    g.addV("Code")
                            .property("json",method.methodAST)
                            .property("lineno",method.methodLineNo)
                            .property("belongFile",method.belongFile)
                            .property("functionDefName","")
                            .next();
                }
                for(CFG cfg : singleFileTotal.cfgList){
                    /*System.out.println(cfg.fromCodeLabel);
                    System.out.println(cfg.fromCodeAST);
                    System.out.println(cfg.fromCodeLabelLine);
                    System.out.println(cfg.toCodeLabel);
                    System.out.println(cfg.toCodeAST);
                    System.out.println(cfg.toCodeLabelLine);*/
                    g.V().hasLabel("Code")
                            .has("lineno",cfg.fromCodeLabelLine)
                            .has("json",cfg.fromCodeAST)
                            .as("fromNode")
                            .V()
                            .hasLabel("Code")
                            .has("lineno",cfg.toCodeLabelLine)
                            .has("json",cfg.toCodeAST)
                            .addE("cfg")
                            .from("fromNode")
                            .next();
                }
                for(PDG pdg : singleFileTotal.pdgList){
                    g.V().hasLabel("Code")
                            .has("lineno",pdg.fromCodeLabelLine)
                            .has("json",pdg.fromCodeAST)
                            .as("fromNode")
                            .V()
                            .hasLabel("Code")
                            .has("lineno",pdg.toCodeLabelLine)
                            .has("json",pdg.toCodeAST)
                            .addE("pdg")
                            .from("fromNode")
                            .next();
                    /*System.out.println(pdg.fromCodeLabel);
                    System.out.println(pdg.fromCodeAST);
                    System.out.println(pdg.fromCodeLabelLine);
                    System.out.println(pdg.toCodeLabel);
                    System.out.println(pdg.toCodeAST);
                    System.out.println(pdg.toCodeLabelLine);*/
                }
            }
            for (CG cg :allFileTotal.cgList){
                System.out.println(cg.fromCodeBelongFile);
                System.out.println(cg.fromCodeAST);
                System.out.println(cg.toCodeBelongFile);
                System.out.println(cg.toCodeAST);
                Optional<Vertex> fromNode = g.V()
                        .hasLabel("Code")
                        .has("belongFile",cg.fromCodeBelongFile)
                        .has("json",cg.fromCodeAST)
                        .tryNext();
                Optional<Vertex> toNode = g.V()
                        .hasLabel("Code")
                        .has("belongFile",cg.toCodeBelongFile)
                        .has("json",cg.toCodeAST)
                        .tryNext();
                if (fromNode.isPresent() && toNode.isPresent()) {
                    fromNode.get().addEdge("cg", toNode.get());
                }
                /*g.V().hasLabel("Code")
                        .has("belongFile",cg.fromCodeBelongFile)
                        .has("json",cg.fromCodeAST)
                        .as("fromNode")
                        .V()
                        .hasLabel("Code")
                        .has("belongFile",cg.toCodeBelongFile)
                        .has("json",cg.toCodeAST)
                        .addE("cg")
                        .from("fromNode")
                        .tryNext();*/
            }
            g.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("Store finished");
    }

    private static List<Folder> getFolderListbyFilePath(List<Folder> folderList, String filePath) {
        String[] splitFolderList = filePath.split("\\\\");
        String Folder="";
        List<Folder> result = new ArrayList<>();
        boolean hasFolder = false;
        for(int i=0;i<splitFolderList.length;i++){
            if(i!=0){
                Folder+="/";
            }
            Folder+=splitFolderList[i];
            for(Folder folder: folderList){
                if(folder.folderName.equals(Folder)){
                    hasFolder = true;
                    break;
                }
            }
            if(!hasFolder){
                for (int j=i+1;j<splitFolderList.length;j++){
                    result.add(new Folder(Folder));
                    Folder += "/";
                    Folder+=splitFolderList[j];
                }
                break;
            }
        }
        return result;
    }

    public static SingleFileTotal parsePDG(File file,File ASTFile) throws IOException {
        BufferedReader FileReader = new BufferedReader(new FileReader(file));
        BufferedReader ASTFileReader = new BufferedReader(new FileReader(ASTFile));
        StringBuilder stringBuilder = new StringBuilder();
        char[] buffer = new char[99999];
        int len;
        while ((len = ASTFileReader.read(buffer)) != -1) {
            stringBuilder.append(new String(buffer, 0, len));
            buffer = new char[99999];
        }
        ASTFileReader.close();
        String ASTJsonString = stringBuilder.toString();
        Gson gson = new Gson();
        ASTJSON ASTJson = gson.fromJson(ASTJsonString,ASTJSON.class);
        String rootDir = System.getProperty("user.dir").replace("\\","/")+"/";
        String Line;
        SingleFileTotal singleFileTotal = new SingleFileTotal();
        String method="";
        String className="";
        String classFieldName="";
        String classFieldLabel="";
        String classFieldLine="";
        boolean refresh=true;
        boolean inField = false;
        while((Line = FileReader.readLine())!=null){
            if(Line.startsWith("classfield:")&&!inField){
                classFieldName=Line.substring(11);
                className=classFieldName;
                inField=true;
            }
            else if(inField&&Line.equals("}")){
                inField=false;
            }
            else if(Line.startsWith("v:")&&!inField){
                if(!Line.startsWith("Enter Enter", 3)){
                    int firstSpace = Line.indexOf(" ");
                    int lastSpace = Line.lastIndexOf(" ");
                    String label = Line.substring(firstSpace+1,lastSpace);
                    int lineNo = Integer.parseInt(Line.substring(lastSpace+1));
                    String vertexASTJson = getVertexASTJson(label,lineNo,ASTJson);
                    //System.out.println(vertexASTJson);
                    singleFileTotal.codeList.add(new Code(vertexASTJson,Line.substring(lastSpace+1),className+":"+method,
                            singleFileTotal.fileName.replace(".java","").replace("\\","/"),label));
                }
                else {
                    int lastSpace = Line.lastIndexOf(" ");
                    int lastDot = Line.lastIndexOf(".");
                    singleFileTotal.codeList.add(new Code("Enter Enter",Line.substring(lastSpace+1,lastDot),className+":"+method,
                            singleFileTotal.fileName.replace(".java","").replace("\\","/"),"Enter Enter"));
                    if(refresh){
                        refresh = false;
                        int methodListSize=singleFileTotal.methodList.size()-1;
                        singleFileTotal.pdgList.add(new PDG(singleFileTotal.methodList.get(methodListSize).methodName,singleFileTotal.methodList.get(methodListSize).methodLineNo,"Enter Enter",Line.substring(lastSpace+1,lastDot),
                                singleFileTotal.methodList.get(methodListSize).methodAST,
                                getASTJsonbyLabelandLineno("Enter Enter",Line.substring(lastSpace+1,lastDot),singleFileTotal.codeList)
                        ));
                    }
                }
            }
            else if(Line.startsWith("v:")&&inField){
                int firstSpace = Line.indexOf(" ");
                int lastSpace = Line.lastIndexOf(" ");
                String label = Line.substring(firstSpace+1,lastSpace);
                String vertexASTJson = label;
                singleFileTotal.codeList.add(new Code(vertexASTJson,Line.substring(lastSpace+1),className+":CLASSMEMBERVARIABLE",
                        singleFileTotal.fileName.replace(".java","").replace("\\","/"),label));
                classFieldLabel=label;
                classFieldLine=Line.substring(lastSpace+1);
            }
            else if(Line.startsWith("FilePath:")){
                singleFileTotal.fileName=Line.substring(9).replace(".java","").replace("\\","/").replace(rootDir,"");
            }
            else if(Line.startsWith("method:")){
                String[] methodInfos = Line.split(" ");
                method=methodInfos[0].substring(7);
                String methodAST = singleFileTotal.fileName+":"+method+"(";
                for(int i=1;i<methodInfos.length-1;i++){
                    methodAST+=methodInfos[i].substring(0,methodInfos[i].indexOf(":"));
                    methodAST+=",";
                }
                if(methodAST.endsWith(",")){
                    methodAST=methodAST.substring(0,methodAST.lastIndexOf(","));
                }
                methodAST+=")";
                singleFileTotal.methodList.add(new Method(method,methodAST,methodInfos[methodInfos.length-1].split(":")[0],singleFileTotal.fileName));
                if(classFieldName.equals(className)){
                    singleFileTotal.pdgList.add(new PDG(classFieldLabel,classFieldLine,method,methodInfos[methodInfos.length-1].split(":")[0],
                            getASTJsonbyLabelandLineno(classFieldLabel,classFieldLine,singleFileTotal.codeList),
                            methodAST
                    ));
                }
            }
            else if(Line.startsWith("estart:")){
                if(!Line.substring(8).equals("Enter Enter")){
                    String fromCodeLabel = Line.substring(8);
                    Line=FileReader.readLine();
                    int dotIndex = Line.lastIndexOf(".");
                    int lastSpace = Line.lastIndexOf(" ");
                    String toCodeLabel = Line.substring(6,lastSpace);
                    String fromCodeLabelLine = Line.substring(lastSpace+1,dotIndex);
                    String toCodeLabelLine = Line.substring(dotIndex+1);
                    singleFileTotal.pdgList.add(new PDG(fromCodeLabel,fromCodeLabelLine,toCodeLabel,toCodeLabelLine,
                            getASTJsonbyLabelandLineno(fromCodeLabel,fromCodeLabelLine,singleFileTotal.codeList),
                            getASTJsonbyLabelandLineno(toCodeLabel,toCodeLabelLine,singleFileTotal.codeList)));
                }
                else {
                    String fromCodeLabel = Line.substring(8);
                    Line=FileReader.readLine();
                    int dotIndex = Line.lastIndexOf(".");
                    int lastSpace = Line.lastIndexOf(" ");
                    String toCodeLabel = Line.substring(6,lastSpace);
                    String fromCodeLabelLine = Line.substring(lastSpace+1,dotIndex);
                    String toCodeLabelLine = Line.substring(dotIndex+1);
                    singleFileTotal.pdgList.add(new PDG(fromCodeLabel,fromCodeLabelLine,toCodeLabel,toCodeLabelLine,
                            getASTJsonbyLabelandLineno(fromCodeLabel,fromCodeLabelLine,singleFileTotal.codeList),
                            getASTJsonbyLabelandLineno(toCodeLabel,toCodeLabelLine,singleFileTotal.codeList)));
                }
            }
            else if(Line.startsWith("class:")){
                className=Line.substring(6);
            }
            else if(Line.startsWith("{")){
                refresh=true;
            }
            else if(Line.startsWith("package:")){
                singleFileTotal.packageName = Line.substring(8);
            }
            else if(Line.startsWith("import:")){
                singleFileTotal.importNameList.add(Line.substring(7));
            }
        }
        FileReader.close();
        return singleFileTotal;
    }

    public static SingleFileTotal parseCFG(File file,File ASTFile) throws IOException{
        BufferedReader FileReader = new BufferedReader(new FileReader(file));
        BufferedReader ASTFileReader = new BufferedReader(new FileReader(ASTFile));
        StringBuilder stringBuilder = new StringBuilder();
        char[] buffer = new char[99999];
        int len;
        while ((len = ASTFileReader.read(buffer)) != -1) {
            stringBuilder.append(new String(buffer, 0, len));
            buffer = new char[99999];
        }
        ASTFileReader.close();
        String ASTJsonString = stringBuilder.toString();
        Gson gson = new Gson();
        ASTJSON ASTJson = gson.fromJson(ASTJsonString,ASTJSON.class);
        String rootDir = System.getProperty("user.dir").replace("\\","/")+"/";
        String Line;
        SingleFileTotal singleFileTotal = new SingleFileTotal();
        String method="";
        String className="";
        String classFieldName="";
        String classFieldLabel="";
        String classFieldLine="";
        Method methodInfo = new Method("","","","");
        boolean refresh=true;
        boolean inField = false;
        while((Line = FileReader.readLine())!=null){
            if(Line.startsWith("classfield")&&!inField){
                classFieldName=Line.substring(11);
                className=classFieldName;
                inField=true;
            }
            else if(inField&&Line.equals("}")){
                inField=false;
            }
            else if(Line.startsWith("v:")&&!inField){
                int firstSpace = Line.indexOf(" ");
                int lastSpace = Line.lastIndexOf(" ");
                String label = Line.substring(firstSpace+1,lastSpace);
                int lineNo = Integer.parseInt(Line.substring(lastSpace+1));
                String vertexASTJson = getVertexASTJson(label,lineNo,ASTJson);
                singleFileTotal.codeList.add(new Code(vertexASTJson,Line.substring(lastSpace+1),className+":"+method,
                        singleFileTotal.fileName.replace(".java","").replace("\\","/"),label));
                if(refresh){
                    refresh=false;
                    singleFileTotal.cfgList.add(new CFG(methodInfo.methodName,methodInfo.methodLineNo,label,Line.substring(lastSpace+1),
                            methodInfo.methodAST,
                            getASTJsonbyLabelandLineno(label,Line.substring(lastSpace+1),singleFileTotal.codeList)
                    ));
                }
            }
            else if(Line.startsWith("v:")&&inField){
                int firstSpace = Line.indexOf(" ");
                int lastSpace = Line.lastIndexOf(" ");
                String label = Line.substring(firstSpace+1,lastSpace);
                String vertexASTJson = label;
                singleFileTotal.codeList.add(new Code(vertexASTJson,Line.substring(lastSpace+1),className+":CLASSMEMBERVARIABLE",
                        singleFileTotal.fileName.replace(".java","").replace("\\","/"),label));
                classFieldLabel=label;
                classFieldLine=Line.substring(lastSpace+1);
            }
            else if(Line.startsWith("FilePath:")){
                singleFileTotal.fileName=Line.substring(9).replace(".java","").replace("\\","/").replace(rootDir,"");
            }
            else if(Line.startsWith("method:")){
                String[] methodInfos = Line.split(" ");

                method=methodInfos[0].substring(7);
                String methodAST = singleFileTotal.fileName+":"+method+"(";
                for(int i=1;i<methodInfos.length-1;i++){
                    methodAST+=methodInfos[i].substring(0,methodInfos[i].indexOf(":"));
                    methodAST+=",";
                }
                if(methodAST.endsWith(",")){
                    methodAST=methodAST.substring(0,methodAST.lastIndexOf(","));
                }
                methodAST+=")";
                methodInfo=new Method(method,methodAST,methodInfos[methodInfos.length-1].split(":")[0],singleFileTotal.fileName);
                if(classFieldName.equals(className)){
                    singleFileTotal.cfgList.add(new CFG(classFieldLabel,classFieldLine,method,methodInfos[methodInfos.length-1].split(":")[0],
                            getASTJsonbyLabelandLineno(classFieldLabel,classFieldLine,singleFileTotal.codeList),
                            methodAST
                    ));
                }
            }
            else if(Line.startsWith("estart:")){
                String fromCodeLabel = Line.substring(8);
                Line=FileReader.readLine();
                int dotIndex = Line.lastIndexOf(".");
                int lastSpace = Line.lastIndexOf(" ");
                String toCodeLabel = Line.substring(6,lastSpace);
                String fromCodeLabelLine = Line.substring(lastSpace+1,dotIndex);
                String toCodeLabelLine = Line.substring(dotIndex+1);
                singleFileTotal.cfgList.add(new CFG(fromCodeLabel,fromCodeLabelLine,toCodeLabel,toCodeLabelLine,
                        getASTJsonbyLabelandLineno(fromCodeLabel,fromCodeLabelLine,singleFileTotal.codeList),
                        getASTJsonbyLabelandLineno(toCodeLabel,toCodeLabelLine,singleFileTotal.codeList)));
            }
            else if(Line.startsWith("class:")){
                className=Line.substring(6);
            }
            else if(Line.startsWith("classfield:")){
                className=Line.substring(11);
            }
            else if(Line.startsWith("{")){
                refresh=true;
            }
        }
        FileReader.close();
        return singleFileTotal;
    }

    public static List<CG> parseCG(File file) throws IOException {
        BufferedReader FileReader = new BufferedReader(new FileReader(file));
        String Line;
        List<CG> cgList = new ArrayList<>();
        String filePath;
        String rootPath;
        while((Line = FileReader.readLine())!=null){
            if(Line.startsWith("FilePath:")){
                filePath = Line.substring(9);
            }
            else if(Line.startsWith("RootPath:")){
                rootPath=Line.substring(9);
            }
            else if(Line.startsWith("method:")){
                ;
            }
            else if(Line.startsWith("{")){
                ;
            }
            else if(Line.startsWith("}")){
                ;
            }
            else {
                Line = Line.replace(" ","").replace(";","");
                String[] node = Line.split("->");
                String fromCode = node[0];
                String toCode = node[1];
                cgList.add(getCGNode(fromCode,toCode));
            }
        }
        FileReader.close();
        return cgList;
    }

    private static String getVertexASTJson(String label, int lineNo, ASTJSON ASTJson) {
        String vertexASTJson="";
        for(MethodJSON methodJSON : ASTJson.methodJSONList){
            if(methodJSON.startLine<=lineNo&&methodJSON.endLine>=lineNo){
                vertexASTJson = getVertexASTJsonInASTNodeJSON(label,lineNo,methodJSON.astNodeJSON);
                break;
            }
        }
        return vertexASTJson;
    }

    private static String getVertexASTJsonInASTNodeJSON(String label, int lineNo, ASTNodeJSON astNodeJSON){
        String vertexASTJson="";
        for(ASTNodeJSON childAstNodeJSON : astNodeJSON.childNodeList){
            if(childAstNodeJSON.startLine<=lineNo&&childAstNodeJSON.endLine>=lineNo){
                if(childAstNodeJSON.startLine==childAstNodeJSON.endLine){
                    if(label.replace(" ","").equals(childAstNodeJSON.label.replace(" ",""))){
                        //Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
                        Gson gson = new GsonBuilder().disableHtmlEscaping().create();
                        vertexASTJson=gson.toJson(childAstNodeJSON);
                        vertexASTJson=vertexASTJson.replace("\\\\\\","\\");
                        break;
                    }
                }
                else {
                    vertexASTJson = getVertexASTJsonInASTNodeJSON(label,lineNo,childAstNodeJSON);
                    break;
                }
            }
        }
        return vertexASTJson;
    }

    private static String getASTJsonbyLabelandLineno(String label,String lineno,List<Code> codeList){
        for(Code code : codeList){
            /*System.out.println(code.lineno);
            System.out.println(code.codeLabel);
            System.out.println(lineno);
            System.out.println(label);*/
            if(code.lineno.equals(lineno)&&code.codeLabel.equals(label)){
                return code.json;
            }
        }
        //System.out.println("NO!!!!!!!!!");
        return "Something wrong in correspond!";
    }

    private static CG getCGNode(String fromCode,String toCode){
        String fromCodeLabel = "";
        String fromCodeBelongFile = "input/";
        String fromCodeAST = "";
        if(fromCode.startsWith(".")){
            fromCode = fromCode.substring(1);
        }
        int leftkuohaooffromCode = fromCode.indexOf("(");
        int righkuohaooffromCode = fromCode.indexOf(")");
        String fromCodeMethod = fromCode.substring(0,leftkuohaooffromCode);
        String fromCodeParameter = fromCode.substring(leftkuohaooffromCode+1,righkuohaooffromCode);
        String[] fromPathSplit = fromCodeMethod.split("\\.");
        String[] fromParameterSplit = fromCodeParameter.split(",");
        for(int i=0;i<fromPathSplit.length-2;i++){
            fromCodeBelongFile+=fromPathSplit[i];
            fromCodeBelongFile+="/";
        }
        fromCodeBelongFile+=fromPathSplit[fromPathSplit.length-2];
        fromCodeLabel = fromPathSplit[fromPathSplit.length-1];
        fromCodeAST = fromCodeBelongFile+":"+fromCodeLabel+"(";
        String parameter = fromParameterSplit[0];
        fromCodeAST+=parameter;
        //if(parameter)else{}
        for(int i=1;i<fromParameterSplit.length;i++){
            parameter = fromParameterSplit[i];
            //if(parameter)else{}
            fromCodeAST+=",";
            fromCodeAST+=parameter;
        }
        fromCodeAST+=")";
        String toCodeLabel = "";
        String toCodeBelongFile = "input/";
        String toCodeAST = "";
        if(toCode.startsWith(".")){
            toCode = toCode.substring(1);
        }
        int leftkuohaooftoCode = toCode.indexOf("(");
        int righkuohaooftoCode = toCode.indexOf(")");
        String toCodeMethod = toCode.substring(0,leftkuohaooftoCode);
        String toCodeParameter = toCode.substring(leftkuohaooftoCode+1,righkuohaooftoCode);
        String[] toPathSplit = toCodeMethod.split("\\.");
        String[] toParameterSplit = toCodeParameter.split(",");
        for(int i=0;i<toPathSplit.length-2;i++){
            toCodeBelongFile+=toPathSplit[i];
            toCodeBelongFile+="/";
        }
        toCodeBelongFile+=toPathSplit[toPathSplit.length-2];
        toCodeLabel = toPathSplit[toPathSplit.length-1];
        toCodeAST = toCodeBelongFile+":"+toCodeLabel+"(";
        parameter = toParameterSplit[0];
        toCodeAST+=parameter;
        //if(parameter)else{}
        for(int i=1;i<toParameterSplit.length;i++){
            parameter = toParameterSplit[i];
            //if(parameter)else{}
            toCodeAST+=",";
            toCodeAST+=parameter;
        }
        toCodeAST+=")";
        return new CG(fromCodeLabel,fromCodeBelongFile,toCodeLabel,fromCodeAST,toCodeAST,toCodeBelongFile);
    }
}
